/*启动后端项目*/
import { init } from "@/run/init";
import { Controller, useKoaServer,useContainer } from "routing-controllers";
import { Container } from "typedi";
import { join } from "path";
import "reflect-metadata";

class App extends init {
    app:typeof this.koa
    constructor(){
        super()
        useContainer(Container)
        
        this.app= useKoaServer(this.koa,{
            cors:this.config.cors.configCors,
            validation:true,
            classTransformer:true,
            controllers: [ `${join(__dirname, '../controller/**/*{.js,.ts}')}` ]
        })
        this.run()
    }

    run(){
        this.app.listen(this.config.port, ()=>{
            console.log( `
            👏  博客后端接口 👏
            👉  1：PC官网: http://127.0.0.1:${this.config.port}/
            👉  2：Admin后台: xxxxx
            `);  
        }) //支持回调参数

        this.app.on('error', (err, ctx) => {
            console.error('server error', err, ctx)
        });
    }
}


new App();